<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 逐个交换至前面合适的位置
        for (let i = 1; i < nums.length; i++) {
            for (let j = 0; j < nums.length; j++) {
                if (nums[i] < nums[j]) {
                    let temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }

        // 暂存变量，然后将前面的若干个元素诸葛向后负值
        for (let i = 1; i < nums.length; i++) {
            let num = nums[i];
            let j = i;
            while (j > 0 && nums[j - 1] > num) {
                nums[j] = nums[j - 1];
                j--;
            }

            nums[j] = num;
        }
    </script>
</body>

</html>